﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2010
 */

#region Using
using System;
using System.Collections.Generic;
using System.Data.Common;
using NetBay.Core.BusinessEntities;
using NetBay.Core.Log;
using System.Data;
#endregion

namespace Rio.Windows.Services.TranslatorLayer
{
    /// <summary>
    /// Class used to convert Group database row to Group object
    /// </summary>
    public class GeneralGroupTranslator
    {
       
            /// <summary>
            /// Translate a bunch of Group DataReader to Group object
            /// </summary>
            /// <param name="P_oDbDataReader">The dataReader that contains the rows</param>
            /// <returns>A list of Group Object</returns>
        public static List<Group> TranslateGroup(IDataReader P_oDbDataReader)
            {
                List<Group> l_lstGroups = new List<Group>();
                try
                {
                        while (P_oDbDataReader.Read())
                        {
                            Group l_oGroup = new Group();

                            l_oGroup.Identifier = Convert.ToInt32(P_oDbDataReader["RG_ID"].ToString());
                            l_oGroup.Name = P_oDbDataReader["RG_NOM"].ToString();
                            l_oGroup.CanConsult = Convert.ToBoolean(Convert.ToInt16(P_oDbDataReader["RG_CONS"].ToString()));
                            l_oGroup.CanReorganize = Convert.ToBoolean(Convert.ToInt16(P_oDbDataReader["RG_REORG"].ToString()));
                            l_oGroup.IsAdministrator = Convert.ToBoolean(Convert.ToInt16(P_oDbDataReader["RG_ADMIN"].ToString()));
                            l_oGroup.CanScann = Convert.ToBoolean(Convert.ToInt16(P_oDbDataReader["RG_NUM"].ToString()));
                            l_oGroup.CanPrint = Convert.ToBoolean(Convert.ToInt16(P_oDbDataReader["RG_IMPRESSION"].ToString()));
                            l_oGroup.CanDownload = Convert.ToBoolean(Convert.ToInt16(P_oDbDataReader["RG_TELECHARGER"].ToString()));
                            l_oGroup.CanSendEmail = Convert.ToBoolean(Convert.ToInt16(P_oDbDataReader["RG_EMAIL"].ToString()));

                            l_lstGroups.Add(l_oGroup);
                        }
                }
                catch (Exception ex)
                {
                    LogManager.Instance().LogError(NetBay.Core.Diagnostics.Method.GetMethodBaseName(NetBay.Core.Diagnostics.Method.Level.Father) + " EXCEPTION -> " + Environment.NewLine + ex);
                }

                return l_lstGroups;
            }
        }
    
}



